package cn.dhn_app.horseman_app.controller;

import cn.dhn_app.horseman_app.service.HorsemanCreateAccountService;
import cn.itcast.pojo.horseman;
import cn.itcast.util.ResponseEntity;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author: 张松
 * @Description:
 * @Date: Created in 9:51 2020/8/25
 * @Modified By:
 */
@RestController
@RequestMapping("HorsemanCreateAccountController")
@Slf4j
public class HorsemanCreateAccountController {

    @Resource
    private HorsemanCreateAccountService horsemanCreateAccountService;

    /**
     *
     * @Description: App骑手端注册
     *
     * @auther: 张松
     * @date: 10:32 2020/8/25
     * @param: [horseman]
     * @return: cn.itcast.util.ResponseEntity
     */
    @PostMapping("horsemanCreateAccount")
    public ResponseEntity horsemanCreateAccount(@RequestBody Map<String,Object> map){
        log.info("注册开始");

        LinkedHashMap linkedHashMap = (LinkedHashMap) map.get("horseman");
        String s = new JSONObject().toJSONString(linkedHashMap);
        horseman horseman = JSON.parseObject(s, horseman.class);
        Integer phoneCode = Integer.parseInt(map.get("phoneCode").toString());
        ResponseEntity responseEntity = horsemanCreateAccountService.horsemanCreateAccount(horseman,phoneCode);
        return  responseEntity;
    }


}
